home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / rpmhash.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  2.7 KB  |  108 lines

  1. #ifndef H_RPMHASH
  2. #define H_RPMHASH
  3.  
  4. /**
  5.  * \file rpmdb/rpmhash.h
  6.  * Hash table implemenation.
  7.  */
  8.  
  9. /**
  10.  */
  11. typedef /*@abstract@*/ struct hashTable_s * hashTable;
  12.  
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16.  
  17. /**
  18.  */
  19. typedef unsigned int (*hashFunctionType) (const void * string)
  20.     /*@*/;
  21.  
  22. /**
  23.  */
  24. typedef int (*hashEqualityType) (const void * key1, const void * key2)
  25.     /*@*/;
  26.  
  27. /**
  28.  * Return hash value of a string
  29.  * @param string    string on which to calculate hash value
  30.  * @return        hash value
  31.  */
  32. unsigned int hashFunctionString(const void * string)
  33.     /*@*/;
  34.  
  35. /**
  36.  * Compare two hash table entries for equality.
  37.  * @param key1          entry 1
  38.  * @param key2          entry 2
  39.  * @return        0 if entries are equal
  40.  */
  41. int hashEqualityString(const void * key1, const void * key2)
  42.     /*@*/;
  43.  
  44. /**
  45.  * Create hash table.
  46.  * If keySize > 0, the key is duplicated within the table (which costs
  47.  * memory, but may be useful anyway.
  48.  * @param numBuckets    number of hash buckets
  49.  * @param keySize       size of key (0 if unknown)
  50.  * @param freeData      Should data be freed when table is destroyed?
  51.  * @param fn            function to generate hash value for key
  52.  * @param eq            function to compare hash keys for equality
  53.  * @return        pointer to initialized hash table
  54.  */
  55. hashTable htCreate(int numBuckets, int keySize, int freeData,
  56.         hashFunctionType fn, hashEqualityType eq)
  57.     /*@*/; 
  58.  
  59. /**
  60.  * Destroy hash table.
  61.  * @param ht            pointer to hash table
  62.  * @return        NULL always
  63.  */
  64. /*@null@*/
  65. hashTable htFree( /*@only@*/ hashTable ht)
  66.     /*@modifies ht @*/;
  67.  
  68. /**
  69.  * Add item to hash table.
  70.  * @param ht            pointer to hash table
  71.  * @param key           pointer to key
  72.  * @param data          pointer to data value
  73.  */
  74. void htAddEntry(hashTable ht, /*@owned@*/ const void * key,
  75.         /*@owned@*/ const void * data)
  76.     /*@modifies ht */;
  77.  
  78. /**
  79.  * Retrieve item from hash table.
  80.  * @param ht            pointer to hash table
  81.  * @param key           pointer to key value
  82.  * @retval data         address to store data value from bucket
  83.  * @retval dataCount    address to store data value size from bucket
  84.  * @retval tableKey     address to store key value from bucket (may be NULL)
  85.  * @return        0 on success, 1 if the item is not found.
  86.  */
  87. int htGetEntry(hashTable ht, const void * key,
  88.         /*@null@*/ /*@out@*/ const void *** data,
  89.         /*@null@*/ /*@out@*/ int * dataCount,
  90.         /*@null@*/ /*@out@*/ const void ** tableKey)
  91.     /*@modifies *data, *dataCount, *tableKey @*/;
  92.  
  93. /**
  94.  * Check for key in hash table.
  95.  * @param ht            pointer to hash table
  96.  * @param key           pointer to key value
  97.  * @return        1 if the key is present, 0 otherwise
  98.  */
  99. /*@unused@*/
  100. int htHasEntry(hashTable ht, const void * key)
  101.     /*@*/;
  102.  
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106.  
  107. #endif
  108.